package cn.edu.scau.cmi.ChenKaihui.client;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.ChenKaihui.domain.Insurance;
import cn.edu.scau.cmi.ChenKaihui.factory.*;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class FactoryClient extends Application implements Initializable{
	
	@FXML
    public ChoiceBox<String> insuranceChoiceBox;
	
	@FXML
    public TextArea textArea;

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		ObservableList<String> options = FXCollections.observableArrayList("身体受伤","汽车损坏","人员伤亡","多种事故");
        insuranceChoiceBox.setValue("身体受伤");
        insuranceChoiceBox.setItems(options);
	}

	public void displayMessage() {
        String str = insuranceChoiceBox.getValue();
        InsuranceFactory insuranceFactory = null;
        switch (str) {
            case "身体受伤":
                insuranceFactory = new PhysicalFactory();
                break;
            case "汽车损坏":
                insuranceFactory = new VehicleFactory();
                break;
            case "人员伤亡":
                insuranceFactory = new CasualtyFactory();
                break;
            case "多种事故":
                insuranceFactory = new AccidentFactory();
                break;
        }
        if (insuranceFactory != null) {
            Insurance insurance = insuranceFactory.getInstance();
            textArea.setText(insurance.showInsurance());
        }
    }
	
	@Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("../UI/factoryClientUI.fxml"));
        primaryStage.setTitle("工厂模式");
        primaryStage.setScene(new Scene(root, 800, 800));
        primaryStage.setResizable(false);
        primaryStage.show();
    }
	
	public static void main(String[] args) {
		launch(args);
	}

}
